<template>
	<view>
		<view class="m-top">
			<u-tabs :list="listTab" active-color="#fa3534" :is-scroll="false" :current="current" @change="changeTab">
			</u-tabs>
		</view>
		<view class="m-list">
			<view class="m-item u-m-b-25" v-for="(item,index) in list" :key="index"
				@click="to_link('order/detail?id='+item.orders_id)">
				<view class="m-item-title u-border-bottom">
					<text>{{item.room_type_name}}</text>
					<text class="m-font1">{{item.orders_status_text}}</text>
				</view>
				<view class="m-item-con">
					<view class="m-item-img">
						<image :src="item.room_image" mode="aspectFill"></image>
					</view>
					<view class="m-item-con-text">
						<text>{{item.room_num}}间，{{item.bed_type}}</text>
						<text class="u-m-t-10">{{item.start_time}} - {{item.end_time}}</text>
						<text class="u-m-t-10">总价：￥{{item.money}}</text>
					</view>
				</view>
				<view class="u-flex u-row-right u-m-t-25 u-m-b-25">
					<text class="m-btn" @click.stop="pay(item.orders_id)" v-if="item.orders_status==0">支付</text>
					<view class="m-btn" @click.stop="to_link('order/evalForm?marchant_orders_id='+item.orders_id+'&marchant_id='+item.marchant_id)" v-if="item.orders_status==2">评价</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		to_link
	} from "@/common/function/system_fun.js"
	import {
		getOrdersList
	} from "@/common/function/api_fun.js"
	// import {
	// 	startPay
	// } from "@/common/function/pay.js"
	export default {
		data() {
			return {
				current: 0,
				page: 1,
				listTab: [{
						name: '全部',
					},
					{
						name: '待付款',
					},
					{
						name: '待使用',
					},
					{
						name: '待评价',
					},
					{
						name: '退款/售后',
					}
				],
				list: [],
				isLoadFinish: false
			};
		},
		onLoad() {
			this.getOrdersList();
		},
		methods: {
			
			pay(ordersId) {
				startPay(ordersId).then((res) => {
					this.getOrdersList();
			
				}).catch(() => {
					
				})
			},
			getOrdersList() {
				if (this.isLoadFinish) return;
				getOrdersList({
					orders_status: this.current,
					page: this.page
				}).then((res) => {
					console.log(res, 'res res')
					this.list = this.list.concat(res.list)
					if (this.page >= res.total_page) {
						this.isLoadFinish = true;
					}
				})

			},
			changeTab(e) {
				if (e === this.current) return false;

				this.current = e
				this.isLoadFinish = false;
				this.list = [];
				this.getOrdersList()
			
				

			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f4f4f4;
	}

	.m-top {
		width: 750rpx;
		height: 80rpx;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
	}

	.m-font1 {
		font-size: 26rpx;
		color: #333;
		font-weight: 400;
	}

	.m-list {
		display: flex;
		flex-direction: column;
		margin: 105rpx 25rpx 25rpx 25rpx;

		.m-item {
			display: flex;
			flex-direction: column;
			background: #fff;
			border-radius: 14rpx;
			padding: 0 20rpx;

			.m-item-title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 28rpx;
				font-weight: 800;
				height: 80rpx;
			}

			.m-item-con {
				display: flex;
				margin-top: 20rpx;

				.m-item-img {
					display: flex;
					flex-direction: column;
					width: 120rpx;
					height: 120rpx;

					image {
						width: 100%;
						border-radius: 10rpx;
					}
				}

				.m-item-con-text {
					display: flex;
					flex-direction: column;
					width: 570rpx;
					padding-left: 20rpx;
					font-size: 26rpx;
					color: #333;
				}
			}
		}
	}

	.m-btn {
		display: flex;
		padding: 8rpx 25rpx;
		border: 1rpx solid #eeeeee;
		border-radius: 10rpx;
		font-size: 28rpx;
		color: #333;
	}
</style>
